<template>
	<view class="wrap">
		<view class="top"></view>
		<view class="content">
			<view class="title">欢迎登陆极星商城</view>
			<form class="form">
				<input class="u-border-bottom" type="text" v-model="username" placeholder="请输入账号" />
				<input class="u-border-bottom" type="password" v-model="password" placeholder="请输入密码" />
				<button :style="[inputStyle]" :loading="submitBtn" :disabled="submitBtn" class="getCaptcha" @click="getLogin" form-type="submit">账号登录</button>
				<view class="alternative">
					<view class="password" @click="forget">忘记密码</view>
					<view class="issue" @tap="submit">注册账号</view>
				</view>
			</form>
		</view>
		<view class="buttom">
			<view class="loginType">
				<view class="wechat item">
					<view class="icon"><u-icon size="70" name="weixin-fill" color="rgb(83,194,64)"></u-icon></view>
					微信
				</view>
				<view class="QQ item">
					<view class="icon"><u-icon size="70" name="qq-fill" color="rgb(17,183,233)"></u-icon></view>
					QQ
				</view>
			</view>
			<view class="hint">
				登录代表同意
				<text class="link">极星用户协议、隐私政策，</text>
				并授权使用您的极星账号信息（如昵称、头像、收获地址）以便您统一管理
			</view>
		</view>
	</view>
</template>
<script>
export default {
	data() {
		return {
			username: '',
			password: '',
			submitBtn: false
			//token: "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0aGlzIGlzIGxpdGVtYWxsIHRva2VuIiwiYXVkIjoiTUlOSUFQUCIsImlzcyI6IkxJVEVNQUxMIiwiZXhwIjoxNjQwMDU1NTk1LCJ1c2VySWQiOjYwLCJpYXQiOjE2NDAwNDgzOTV9.f1MSv7ThMZaYvGj2GPEcUqVTfa3mlbBWPXNxomq999A"
		};
	},
	computed: {
		inputStyle() {
			let style = {};
			if (this.username && this.password) {
				style.color = '#fff';
				style.backgroundColor = this.$u.color['warning'];
			}
			return style;
		}
	},
	methods: {
		submit() {
			this.$u.route({
				url: 'pages/center/registered'
			});
		},
		forget() {
			uni.navigateTo({
				url:'../user/tools/authReset'
			});
		},
		getLogin() {
			let msg = '';
			if (!this.username || this.username.length < 6) {
				msg = '请输入正确账号';
			}
			if (!this.password || this.password.length < 6) {
				msg = '请输入正确密码';
			}
			if (!msg) {
				this.$post(this.API.authLogin, {
					username: this.username,
					password: this.password
				}).then(res => {
					console.log('dengleng', res);
					if (res.data.errno !== 700) {
						setTimeout(function() {
							uni.switchTab(
								{
									type: 'reLaunch',
									url: '/pages/center/center'
								},
								1500
							);
						});
						uni.showLoading({
							title: '登录中'
						});
						//缓存token
						this.$u.vuex('vuex_token', res.data.data.token);
						this.$u.vuex('vuex_user', res.data.data.userInfo);
						console.log(this.vuex_user);
					} else {
						uni.showToast({
							title: res.data.errmsg
						});
					}
				});
			} else {
				uni.showToast({
					title: msg,
					duration: 2000
				});
			}
		}
	}
};
</script>

<style lang="scss" scoped>
.wrap {
	font-size: 28rpx;
	.content {
		width: 600rpx;
		margin: 80rpx auto 0;

		.title {
			text-align: left;
			font-size: 60rpx;
			font-weight: 500;
			margin-bottom: 100rpx;
		}
		input {
			text-align: left;
			margin-bottom: 10rpx;
			padding-bottom: 6rpx;
		}
		.u-border-bottom {
			padding: 40rpx 0;
		}
		.getCaptcha {
			background-color: rgb(253, 243, 208);
			color: #c8c9cc;
			border: none;
			font-size: 30rpx;
			padding: 20rpx 0;
			margin-top: 40rpx;
			&::after {
				border: none;
			}
		}
		.alternative {
			color: #c8c9cc;
			display: flex;
			justify-content: space-between;
			margin-top: 30rpx;
		}
	}
	.buttom {
		.loginType {
			display: flex;
			padding: 250rpx 150rpx 150rpx 150rpx;
			justify-content: space-between;

			.item {
				display: flex;
				flex-direction: column;
				align-items: center;
				color: #c8c9cc;
				font-size: 28rpx;
			}
		}

		.hint {
			padding: 20rpx 40rpx;
			font-size: 20rpx;
			color: #c8c9cc;

			.link {
				color: #ffaa00;
			}
		}
	}
}
</style>
